package com.tuling.designpattern.command.expand;

import java.util.ArrayList;

/**
 * @author 林瑞涛
 * @desc    调用者
 * @date 2021年08月03日 15:45
 */
public class CompositeInvoker extends AbstractCommand {
    private ArrayList<AbstractCommand> children = new ArrayList<AbstractCommand>();
    public void add(AbstractCommand c) {
        children.add(c);
    }
    public void remove(AbstractCommand c) {
        children.remove(c);
    }
    public AbstractCommand getChild(int i) {
        return children.get(i);
    }
    public void execute() {
        for (Object obj : children) {
            ((AbstractCommand) obj).execute();
        }
    }
}
